// https://leetcode.cn/problems/longest-substring-without-repeating-characters/description/

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int l = 0, r = 0, ans = 0;
        map<char, int> cnt;
        while (r < s.size()) {
            cnt[s[r]]++;
            while (cnt[s[r]] > 1) {
                --cnt[s[l]];
                l++;
            }
            ans = max(ans, r - l + 1);
            r++;
        }
        return ans;
    }
};